(function (app) {
    /**
     * 路由配置
     */
    app.config(['$stateProvider', '$ocLazyLoadProvider', function ($stateProvider, $ocLazyLoadProvider) {
        $ocLazyLoadProvider.config({ // 懒加载配置
            modules: [{ // 富文本编辑器
                name: 'ng.ueditor',
                files: [
                    'vendor/angular/angular-ueditor/angular-ueditor.js'
                ]
            }, { // 文件上传
                name: 'angularFileUpload',
                files: ['vendor/modules/angular-file-upload/angular-file-upload.js']
            }]
        });

        // 注册路由提供者
        iRouter.config({ROUTER_PROVIDER: $stateProvider});
        // 模板
        iRouter.module({
            module: 'template',
            templateResource: 'demo/templates'
        });
        // 布局
        iRouter.module({
            module: 'layout',
            templateResource: 'demo/layouts'
        });
    }]);

    /**
     * 表单路由
     */
    app.config(
            ['$stateProvider', '$urlRouterProvider', 'resolver', function ($stateProvider, $urlRouterProvider, resolver) {
                $stateProvider
                // 基础表单
                    .state('app.form', {
                        url: '/form',
                        template: '<div ui-view></div>',
                        controller: 'basicFormCtrl',
                        controllerAs: 'vm',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load([
										ISS.getResPath('demo/components/form/basic/basic-forms-service.js'),
										ISS.getResPath('demo/components/form/basic/basic-forms-ctrl.js')
                                    ]).then(function () {
                                    });
                                }]
                        }
                    })
                    .state('app.form.basic', {
                        url: '/basic',
                        templateUrl: ISS.getResPath('demo/components/form/basic/basic-forms.html'),
                        resolve: {
                            me: resolver.checkLogin,
                            deps: ['uiLoad', '$http', 'LoginService',
                                function (uiLoad, $http, LoginService) {
                                    var loads = ISS.getMapPath();
                                    loads.push(ISS.getResPath('demo/components/form/basic/basic-forms-service.js'));
                                    loads.push(ISS.getResPath('demo/components/form/basic/basic-forms-ctrl.js'));
                                    // loads.push(ISS.getResPath('js/services/HeaderSearchService.js'));
                                    return uiLoad.load(loads).then(function () {

                                    });
                                }]
                        }
                    })
                    .state('app.template.tree', {
                        url: '/tree',
                        templateUrl: ISS.getResPath('demo/components/tree/tree-list.html'),
                        controller:"treeCtrl",
                        controllerAs:"vm",
                        resolve: {
                            me: resolver.checkLogin,
                            module: function(){
                                return {name: ""};
                            },
                            deps: ['uiLoad', '$http', 'LoginService',
                                function (uiLoad, $http, LoginService) {
                                    var loads = ISS.getMapPath();
                                    loads.push(ISS.getResPath('demo/components/tree/tree-service.js'));
                                    loads.push(ISS.getResPath('demo/components/tree/tree-list-ctrl.js'));
                                   loads.push(ISS.getResPath('demo/components/tree/tree-edit-ctrl.js'));
                                    return uiLoad.load(loads).then(function () {
                                    });
                                }]
                        }
                    })
                    //按钮
                    .state('app.form.button', {
                        url: '/button',
                        templateUrl: ISS.getResPath('demo/components/form/button/button-list.html'),
                    })
                    //单选和复选框
                    .state('app.form.check', {
                        url: '/checkbox',
                        controller:"checkBox-list",
                        templateUrl: ISS.getResPath('demo/components/form/checkBox/checkBox-list.html'),
                        controllerAs:"vm",
                        resolve: {
                            me: resolver.checkLogin,
                            deps: ['uiLoad', '$http', 'LoginService',
                                function (uiLoad, $http, LoginService) {
                                    var loads = ISS.getMapPath();
                                    loads.push(ISS.getResPath('demo/components/form/checkBox/checkBox-list.js'));
                                    return uiLoad.load(loads).then(function () {
                                    });
                                }]
                        }
                    })
                    //提示框
                    .state('app.form.tooltip', {
                        url: '/tooltip',
                        templateUrl: ISS.getResPath('demo/components/form/tooltip/tooltip-list.html'),
                        controller:"tooltip-list-ctrl",
                        controllerAs:"vm",
                        resolve: {
                            me: resolver.checkLogin,
                            deps: ['uiLoad', '$http', 'LoginService',
                                function (uiLoad, $http, LoginService) {
                                    var loads = ISS.getMapPath();
                                    loads.push(ISS.getResPath('demo/components/form/tooltip/tooltip-list-ctrl.js'));
                                    return uiLoad.load(loads).then(function () {
                                    });
                                }]
                        }
                    })
            }]
        );
    
    //列表路由
    app.config(
            ['$stateProvider', '$urlRouterProvider', 'resolver', function ($stateProvider, $urlRouterProvider, resolver) {
                $stateProvider
                .state('app.table', {
                    url: '/table',
                    template: '<div ui-view></div>',
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
									ISS.getResPath('demo/components/table/jqgrid/table-jqgrid-ctrl.js'),
									ISS.getResPath('demo/components/table/jqgrid/table-jqgrid-service.js')
                                ]).then(function () {
                                });
                            }]
                    }
                }).state('app.table.JQGrid', {
                        url: '/JQGrid',
                        templateUrl: ISS.getResPath('demo/components/table/jqgrid/jqgrid.html'),
                        controller: 'JQGridCtrl',
                        controllerAs: 'vm',
                        resolve: {
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load([
										ISS.getResPath('demo/components/table/jqgrid/table-jqgrid-ctrl.js'),
										ISS.getResPath('demo/components/table/jqgrid/table-jqgrid-service.js')
                                    ]).then(function () {
                                    });
                                }]
                        }
                    }).state('app.table.flexigrid', {
                        url: '/flexigrid',
                        templateUrl: ISS.getResPath('demo/components/table/flexigrid/flexigrid.html'),
                        controller: 'table.flexigrid.ctrl',
                        controllerAs: 'vm',
                        resolve: {
                            module: function(){
                            	return {name: ""};
                            },
                            deps: ['$ocLazyLoad',
                                function ($ocLazyLoad) {
                                    return $ocLazyLoad.load([
										ISS.getResPath('demo/components/table/flexigrid/table-flexigrid-ctrl.js'),
                                        ISS.getResPath('demo/components/table/flexigrid/flexigrid-edit-ctrl.js'),
                                        ISS.getResPath('demo/components/table/flexigrid/table-flexigrid-service.js')
                                    ]).then(function () {
                                    });
                                }]
                        }
                    })
            }]
        );
    
    //工作流路由
    app.config(
            ['$stateProvider', '$urlRouterProvider', 'resolver', function ($stateProvider, $urlRouterProvider, resolver) {
                $stateProvider
                .state('app.workflow', {
                    url: '/workflow',
                    template: '<div ui-view></div>',
                    resolve: {
                        deps: ['$ocLazyLoad',
                            function ($ocLazyLoad) {
                                return $ocLazyLoad.load([
									ISS.getResPath('demo/workflow/workflow-service.js'),
									ISS.getResPath('demo/workflow/workflow-list-ctrl.js')
                                ]).then(function () {
                                });
                            }]
                    }
                }).state('app.workflow.modelList', {
                        url: '/modelList',
                        templateUrl: ISS.getResPath('demo/workflow/workflow-model-list.html'),
                        controller: 'workflowCtrl',
                        controllerAs: 'vm'
                }).state('app.workflow.modelAdd', {
                    url: '/modelAdd',
                    templateUrl: ISS.getResPath('demo/workflow/workflow-model-add.html'),
                    controller: 'workflowCtrl',
                    controllerAs: 'vm'
               })  
            }]
        );

})(iApp.module());

